package com.mark.segmentword;

import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

public class IKAnalyzerSegmentWord {
	
	static public String IKAnalyzerSegmentWord(boolean flag,String text){
		StringBuffer tempStr = new StringBuffer();
		StringReader re = new StringReader(text);
		IKSegmenter ik = new IKSegmenter(re,flag);
		Lexeme lex = null;
		try {
			while((lex=ik.next())!=null){
				tempStr.append(lex.getLexemeText()+" ");
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return tempStr.toString();
	}
	
	static public List<String> IKAnalyzerSegmentWord(boolean flag,List<String> textList){
		List<String> tempList = new ArrayList<String>();
		for (String string : textList) {
			StringReader re = new StringReader(string);
			IKSegmenter ik = new IKSegmenter(re,flag);
			Lexeme lex = null;
			StringBuffer tempSB = new StringBuffer();
			try {
				while((lex=ik.next())!=null){
					tempSB.append(lex.getLexemeText()+"  ");
				}
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			tempList.add(tempSB.toString());
		}
		return tempList;
	}

}
